﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;

// ReSharper disable LocalizableElement

namespace WindowsStarter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
            openFileDialog.Filter = "exe文件|*.exe";
            openFileDialog.RestoreDirectory = false;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog.FileName;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int instances = 1;
            if (int.TryParse(textBox3.Text, out instances)
                && !string.IsNullOrWhiteSpace(textBox1.Text))
            {
                for (int i = 0; i < instances; i++)
                {
                    ThreadPool.QueueUserWorkItem(index =>
                    {
                        Console.WriteLine("begin to start instance " + i);
                        Process.Start(textBox1.Text, textBox2.Text);
                    }, i);
                }
            }
        }
    }
}
